package com.xiyu.service.repository.devops.project;

import com.xiyu.service.vo.infra.devops.project.ProjectPageQueryInput;
import com.xiyu.service.model.devops.project.DevopsProject;
import com.xiyu.service.model.devops.project.DevopsProjectTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;

import java.util.List;

public interface DevopsProjectRepository extends JRepository<DevopsProject, Long> {
    DevopsProjectTable devopsProjectTable = DevopsProjectTable.$;

    default Page<DevopsProject> pageQuery(ProjectPageQueryInput inputVO){
        return sql().createQuery(devopsProjectTable)
                .whereIf(StringUtils.hasText(inputVO.getName()), () -> devopsProjectTable.name().like(inputVO.getName()))
                        .orderBy(devopsProjectTable.id().desc())
                        .select(devopsProjectTable).fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }

    default List<DevopsProject> listQuery(){
        return sql().createQuery(devopsProjectTable)
                .orderBy(devopsProjectTable.id().desc())
                .select(devopsProjectTable).execute();
    }


}